def is_pr(n):
    if n <= 1:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False

    for d in range(3, int(n ** 0.5) + 1, 2):
        if n % d == 0:
            return False
    return True


def w_to_n(words):
    wo_to_di = {
        "zero": "0", "one": "1", "two": "2", "three": "3",
        "four": "4", "five": "5", "six": "6", "seven": "7",
        "eight": "8", "nine": "9"
    }
    try:
        numb = int(''.join(wo_to_di[w] for w in words))
        if 100 <= numb <= 999:
            return numb
        else:
            print("Wrong input")
            exit()
    except KeyError:
        print("Wrong input")
        exit()


words = input().strip().split()
if len(words) != 3:
    print("Wrong input")
    exit()

n = w_to_n(words)

c = 0
while True:
    if is_pr(n - c):
        print(n - c)
        break
    if is_pr(n + c):
        print(n + c)
        break
    c += 1
